package com.css.fxfzysx.modules.vaomeFacilities.controller;

import cn.hutool.core.io.FileUtil;
import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.modules.vaomeFacilities.service.ImportDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 数据导入
 */
@RestController
@RequestMapping("importData")
public class ImportDataController {

    @Autowired
    private ImportDataService importDataService;

    /**
     * 输油,输气,水库大坝,其他重大工程导入
     */
    @PostMapping("importMajorProjectsData")
    public RestResponse importMajorProjectsData(@RequestParam MultipartFile file,
                                                @RequestParam String type) {
        if (!FileUtil.getSuffix(file.getOriginalFilename()).equals("xls") && !FileUtil.getSuffix(file.getOriginalFilename()).equals("xlsx")) {
            return RestResponse.fail("文件格式不支持!");
        }
        return importDataService.importMajorProjectsData(file,type);
    }

    /**
     * 核电站导入
     */
    @PostMapping("importNpsData")
    public RestResponse importNpsData(@RequestParam MultipartFile file) {
        if (!FileUtil.getSuffix(file.getOriginalFilename()).equals("xls") && !FileUtil.getSuffix(file.getOriginalFilename()).equals("xlsx")) {
            return RestResponse.fail("文件格式不支持!");
        }
        return importDataService.importNpsData(file);
    }

    /**
     * 历史震害数据导入
     */
    @PostMapping("importHeDamageData")
    public RestResponse importHeDamageData(@RequestParam MultipartFile file) {
        if (!FileUtil.getSuffix(file.getOriginalFilename()).equals("xls") && !FileUtil.getSuffix(file.getOriginalFilename()).equals("xlsx")) {
            return RestResponse.fail("文件格式不支持!");
        }
        return importDataService.importHeDamageData(file);
    }
}
